<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <%--多附件上传css--%>
    <link rel="stylesheet" href="<s:url value="/assets/css/main.css"></s:url>"/>
</head>
<style>
    body {
        background: #fff;
    }

    .SelectFiles {
        display: inline-block;
        position: absolute;
        font-size: 14px;
        color: #fff;
        left: 23px;
        top: 5px;
        width: 76px;
        height: 27px;
        background: #6FB3E0;
        text-align: center;
        border-radius: 5px;
        line-height: 25px;
        cursor: pointer;
    }

    button.btn {
        border-radius: 5px;
    }
    .FeedbackContent1{
        cursor: pointer !important;
    }
</style>
<body>
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>
<%--taskBackNews--%>
<form:form commandName="taskSub" cssClass="form-horizontal" role="form" onsubmit="return false;"
           enctype="multipart/form-data" id="feedbackForms">
    <div class="form-group">
        <h3 class="col-sm-offset-2  col-sm-5">反馈汇总</h3>
    </div>
    <div class="row">
        <div class="form-group">
            <h4 class="col-sm-offset-1 col-sm-1 text-right control-label">子事项:</h4>
            <div class="col-sm-8">
                <textarea rows="3" readonly class="form-control" type="text" style="resize: vertical;min-height: 50px">${taskSub.subName}</textarea>
            </div>
        </div>
    </div>
    <c:forEach items="${taskBackNews}" var="task">
        <hr/>
        <div class="information2 row">
        <div class="form-group">
            <label class="control-label col-sm-offset-1 col-sm-1">反馈单位:</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" value="${task.deptName}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-offset-1 col-sm-1">反馈人:</label>
            <div class="col-sm-4">
                <input type="text" class="form-control" value="${task.senderName}" readonly>
            </div>
            <label class="control-label col-sm-1">反馈时间:</label>
            <div class="col-sm-3">
                <input type="text" class="form-control"
                       value="${task.createDate} ${task.createTime}" readonly>
            </div>
        </div>
        <div class="form-group">
            <%--<label class="control-label col-sm-offset-1 col-sm-1">附件:</label>--%>
            <%--<div class="col-sm-4">--%>
                <%--<c:if test="${not empty task.file}">--%>
                    <%--<button class="btn btn-primary upload-btn" data-id="${task.file}">--%>
                        <%--下载附件--%>
                    <%--</button>--%>
                <%--</c:if>--%>
                <%--<c:if test="${empty task.file}">--%>
                    <%--<input type="text" value="无附件" class=" col-sm-3 form-control" readonly>--%>
                <%--</c:if>--%>
            <%--</div>--%>
            <label class="control-label col-sm-1 col-sm-offset-1">反馈状态:</label>
            <div class="col-sm-3">
                <input type="text" class="form-control"
                       value="${task.status == 0 ? "未处理" :task.status == 1 ? "合格" : task.status == 2 ? "退回重办" : "未知"}"
                       readonly>
            </div>
        </div>
                <%--循环附件下载--%>
            <div class="form-group">
                <label class="control-label col-sm-offset-1 col-sm-1">附件:</label>
                <div class="col-sm-9">
                    <c:if test="${not empty task.files}">
                        <c:forEach items="${task.files}" var="fileMap">
                            <div style="margin-bottom:15px;">
                                <input style="width: 70%;" type="text" class="fileName" readonly
                                       title="${fileMap.fileName}"
                                       value="${fileMap.fileName}" onclick="copyFile(this)">
                                <button class="btn btn-primary file" onclick="download(this)"
                                        FileSysId="${fileMap.file}">
                                    下载附件
                                </button>
                            </div>
                        </c:forEach>
                    </c:if>
                    <c:if test="${empty task.files}">
                        <input type="text" value="无附件" class=" col-sm-3 form-control" readonly>
                    </c:if>
                </div>
            </div>
                <%-----以上为附件下载----%>
        <div class="form-group">
            <label class="control-label col-sm-offset-1 col-sm-1">办理情况:</label>
            <div class="col-sm-8">
                <textarea rows="2" readonly onclick="FeedbackContent(this)" FeedbackContent = "#FeedbackContent1" class="form-control" title="点击复制" type="text" style="resize: vertical;min-height: 50px">${task.content}</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-offset-1 col-sm-1">存在问题:</label>
            <div class="col-sm-8">
                <textarea rows="2" readonly class="form-control" onclick="FeedbackContent(this)" FeedbackContent = "#FeedbackContent2" title="点击复制" type="text" style="resize: vertical;min-height: 50px">${task.problem}</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-offset-1 col-sm-1">下一步计划:</label>
            <div class="col-sm-8">
                <textarea rows="2" readonly class="form-control" onclick="FeedbackContent(this)" FeedbackContent = "#FeedbackContent3" title="点击复制" type="text" style="resize: vertical;min-height: 50px">${task.plan}</textarea>
            </div>
        </div>

        </div>
    </c:forEach>
    <div class="row">
        <div class="form-group">
            <label class="col-sm-offset-1 col-sm-1 text-right ">汇总办理情况：</label>
            <div class="col-sm-8">
                <textarea rows="2" class="form-control" id="FeedbackContent1"  name="subSituation" style="resize: vertical;min-height: 50px">${taskSub.subSituation}</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-offset-1 col-sm-1 text-right ">汇总存在问题：</label>
            <div class="col-sm-8">
                <textarea rows="2" class="form-control" id="FeedbackContent2"  name="subProblem" style="resize: vertical;min-height: 50px">${taskSub.subProblem}</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-offset-1 col-sm-1 text-right ">汇总下一步计划：</label>
            <div class="col-sm-8">
                <textarea rows="2" class="form-control" id="FeedbackContent3"  name="subPlan" style="resize: vertical;min-height: 50px">${taskSub.subPlan}</textarea>
            </div>
        </div>
        <input type="text" hidden value="${taskSub.sysId}" name="sysId">
        <div class="form-group">
            <label class="control-label col-sm-1 col-sm-offset-1">反馈汇总附件:</label>
            <div class="col-sm-8">
      <%--      <c:if test="${not empty taskSub.subSituationFile}">
                &lt;%&ndash;下载&ndash;%&gt;
                <div>
                    <input type="text" readonly value="${taskSub.fileName}">
                    <button class="btn btn-primary" onclick="download(this)" FileSysId ="${taskSub.subSituationFile}">
                        下载附件
                    </button>
                </div>
            </c:if>--%>
                  <c:if test="${not empty taskSub.subSituationFile}">
                      <c:forEach items="${taskSub.subSituationFile}" var="fileMap">
                          <div style="margin-bottom:15px;">
                              <input style="width: 70%;" type="text" class="fileName" readonly
                                     title="${fileMap.fileName}"
                                     value="${fileMap.fileName}" onclick="copyFile(this)">
                              <button class="btn btn-primary file" onclick="download(this)"
                                      FileSysId="${fileMap.file}">
                                  下载附件
                              </button>
                          </div>
                      </c:forEach>
                  </c:if>
                  <c:if test="${empty taskSub.subSituationFile}">
                      <input type="text" value="无附件" class=" col-sm-3 form-control" readonly>
                  </c:if>
                <div>
                    <div id="uploader"></div>
                    <%--<div style="display: inline-block">--%>
                        <%--<input type="file" class="fileBorder" id="fileupload">--%>
                    <%--</div>--%>
                    <%--<div style="display: inline-block">--%>
                        <%--<button class="btn btn-info" onclick="uploadFile(this,'subSituationFile','fileName')">--%>
                            <%--<span class="glyphicon glyphicon-open"></span>上传附件--%>
                        <%--</button>--%>
                    <%--</div>--%>
                    <%--<input type="hidden" id="temporaryFile" name="subSituationFile" value="${taskSub.subSituationFile}"">--%>
                    <%--<input type="hidden" id="temporaryFileName" name="fileName" value="${taskSub.fileName}">--%>
                </div>
                <%--上传--%>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-8">
                <input type="button" id="submitFormButton" class="btn-sm btn-success" value="确定保存"
                       style="border-radius: 5px">
                <input type="button" id="handle" class="btn-sm btn-success" value="办理情况导出"
                       style="border-radius: 5px">
            </div>
        </div>
    </div>
    <input type="hidden" class="taskMainId" value="${taskSub.taskMainId}">
    <%--多附件上传的name和id--%>
    <input type="text" name="subSituationFile" value="" >
    <input type="text" name="fileName" value="" >
</form:form>

<%--多选上传--%>
<script src="<s:url value="/assets/js/dist/easyUploader.jq.js"></s:url>"></script>
<script src="<s:url value="/assets/js/chosen.jquery.js"></s:url>"></script>
<script src="<s:url value="/assets/js/ajaxfileupload.js"></s:url>"></script>
<script src="<s:url value="/assets/js/modal/modal.js"></s:url>"></script>
<script src="<s:url value="/assets/js/date-time/bootstrap-datepicker.js"></s:url>"></script>
<script src="<s:url value="/assets/js/jquery.gritter.js"></s:url>"></script>
<script src="<s:url value="/assets/js/own.js"></s:url>"></script>

<script>
    <%--多文件上传--%>
    var fileStr = "";//id字符串拼接
    var fileNameStr = "";//文件名字符串拼接
    var uploader = easyUploader({
        id: "uploader",
        accept: '.jpg,.png,.doc,.docx,.pdf,.xls,.xlsx,.ppt,.pptx',
        action: '/filesUpload/uploadFiles',
        dataFormat: 'formData',
        maxCount: 10,//允许上传的个数
        maxSize: 2000,//允许上传最大的容量
        multiple: true,
        data: null,
        beforeUpload: function (file, data, args) {
        },
        onChange: function (fileList) {
        },
        onRemove: function (removedFiles, files) {
            console.log('onRemove', removedFiles);
        },
        onSuccess: function (res) {
            console.log('onSuccess', res);
            if (res.data !== undefined && res.data[0] !== undefined) {
                //拼接文件id 和 文件名
                $("input[name='subSituationFile']").val(fileStr += res.data[0].sysid + ",");
                $("input[name='fileName']").val(fileNameStr += res.data[0].oldName + ",");

            }
        },
        onError: function (err) {
            console.log('onError', err);
        },
    });
</script>
<script>
    $(function () {
        //下载附件
        $(".wrrapers").on("click", ".upload-fj", function () {
            var id = $(this).data("id");
            var url = "/filesUpload/download/" + id;
            window.open(url);
        });

        //提交
        $("#submitFormButton").click(function () {
            if($("input[name=fileName]").length>1){
                $("#temporaryFileName").remove();
            }
            if($("input[name=file]").length>1){
                $("#temporaryFile").remove();
            }
            var datas = $("#feedbackForms").serialize();
            console.log(datas);
            $.ajax({
                url: "/taskMain/collect/",
                data: datas,
                dataType: "text",
                type: "post",
                success: function (data) {
                    if (data=== "200") {
                        alert("保存成功");
                        setTimeout(function () {
                            open(location, '_self').close();
                        },50)
                    } else {
                        alert("保存失败");
                    }

                }
            })
        })
    })

    /**
     * 动态获取反馈内容
     */
    function FeedbackContent(e){
        var $FeedbackContent = $(e).attr("FeedbackContent");
        var html = $($FeedbackContent).val();
        var text = $(e).val();
        html += text + "；";
        $($FeedbackContent).val(html);
    }

    /*办理实现导出*/
    $("#handle").click(function () {
        var taskMainId = $(".taskMainId").val();
        window.open("/taskMain/exportTaskMain?sysId="+taskMainId);
    })
</script>

</body>
</html>